<template>
    <div class="left_view">
        <div class="top">
            <div class="logo">
                <span>{{$store.state.project_config.name.substring(0,2)}}</span>
                {{$store.state.project_config.name.substring(2)}}
            </div>
            <div class="search">
                <Search_bt></Search_bt>
            </div>
            <div class="item_list">
                <div v-for="(item,index) in item_list" :key="index">
                    <div @click="on_item">
                        <router-link
                            :class="{
                                item:true,
                                on_item:item.router_name.indexOf($route.name) != -1,
                            }" 
                            :to="item.path">
                            <i :class="item.icon"></i>
                            {{item.name}}
                        </router-link>
                    </div>
                    <template v-if="item.divider">
                        <div class="my_divider">
                            <el-divider></el-divider>
                        </div>
                    </template>
                </div>
                <div>
                    <el-badge :value="msg_number" :hidden="msg_number==0">
                        <div @click="on_item">
                            <router-link
                                :class="{
                                    item:true,
                                    on_item:'share'.indexOf($route.name) != -1,
                                }" 
                                to="/disk/share">
                                <i class="el-icon-share"></i>
                                待接收分享
                            </router-link>
                        </div>
                    </el-badge>
                </div>
            </div>
        </div>
        <div class="bottom">
            <!-- <div class="top">
                <div class="left">
                    已用 94.06 KB/10 GB
                </div>
                <div class="right">
                    扩容
                    <i class="el-icon-arrow-right"></i>
                </div>
            </div>
            <div class="bottom">
                <el-progress 
                    :percentage="50"
                    :show-text="false">
                </el-progress>
            </div> -->
        </div>
    </div>
</template>

<script>
import Search_bt from '@/components/public_bt/search_bt';
export default { //左半部分视图
    name: 'Left_view',
    components:{Search_bt},
    data(){
        return{
            item_list:[
                {
                    path:'/disk',
                    name:'全部',
                    router_name:'all|folder',
                    icon:'el-icon-folder-opened',
                    divider:false,
                },
                {
                    path:'/disk/doc',
                    name:'文档',
                    router_name:'doc',
                    icon:'el-icon-document',
                    divider:false,
                },
                {
                    path:'/disk/photo',
                    name:'图片',
                    router_name:'photo',
                    icon:'el-icon-picture-outline',
                    divider:false,
                },
                {
                    path:'/disk/video',
                    name:'视频',
                    router_name:'video',
                    icon:'el-icon-video-play',
                    divider:false,
                },
                {
                    path:'/disk/audio',
                    name:'音乐',
                    router_name:'audio',
                    icon:'el-icon-headset',
                    divider:false,
                },
            ],
            msg_number:0,
            lock:true,
            interval:null,
        };
    },
    created(){
        this.get_msg_number();
        this.interval = setInterval(()=>{ //轮询获取待接收的文件数目
            if(this.lock && this.$route.path != '/login'){
                this.get_msg_number();
            }
        },3000);
    },
    destroyed(){
        if(this.interval){
            clearInterval(this.interval);
        }
    },
    methods:{
        on_item(){  //item被点击就清空，避免重复路由导致清空无效
            this.$store.commit('remove_search_data');
        },
        get_msg_number(){ //获取待接收文件数量
            this.lock = false;
            this.$axios.json_post('/shared/receptCount').then(({data})=>{
                this.msg_number = data;
            }).finally(()=>{
                this.lock = true;
            }).catch(()=>{
                return;
            });
        },
    },
}
</script>

<style scoped lang='scss'>
/deep/.el-badge__content.is-fixed{
    right: 50px;
    top: 10px;
}
.left_view{
    background-color: #f4f4f4;
    width: 230px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    position:sticky;
    top: 0;
    z-index:999;
    //box-shadow: 0 0 8px 0 rgba(232,237,250,.6),0 2px 4px 0 rgba(232,237,250,.5);
    >.top{
        width: 100%;
        >.logo{
            height: 64px;
            padding: 0 25px;
            display: flex;
            justify-content: flex-start;
            align-items: center;
            font-size:25px;
            font-weight: bold;
            letter-spacing: 2px;
            line-height: 100%;
            span{
                margin-right: 2px;
                background-color: #2b2e4a;
                border-radius: 3px;
                color: white;
                padding: 5px 2px;
            }
        }
        >.search{
            padding: 0 25px;
            margin-top: 5px;
        }
        >.item_list{
            margin-top: 20px;
            .my_divider{
                padding: 12px 25px;
                box-sizing: border-box;
                .el-divider--horizontal{
                    margin:0;
                }
            }
            >div{
                width: 100%;
                >div{
                    width: 100%;
                }
            }
            .item{
                box-sizing: border-box;
                height: 40px;
                padding: 5px 20px;
                display: flex;
                justify-content: flex-start;
                align-items: center;
                font-size: 15px;
                color: #555;
                line-height: 100%;
                border-left: 4px solid #297fff00;
                margin: 5px 0;
                i{
                    margin-right: 15px;
                    font-size: 20px;
                    color: #7c878e;
                    transition: all 0.2s;
                }
                &:hover{
                    background: #eaeaea;
                }
            }
            .on_item{
                color: #2980ff;
                font-weight: bold;
                border-left: 4px solid #2980ff;
                i{
                    color: #2980ff;
                    font-weight: bold;
                }
            }
        }
    }
    >.bottom{
        padding: 0 25px 25px 25px;
        width: 100%;
        box-sizing: border-box;
        >.top{
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
            font-size: 12px;
            color: #777;
            line-height: 100%;
            flex-wrap: wrap;
            >div{
                margin-bottom: 5px;
            }
            >.right{
                color: #2980ff;
            }
        }
        >.bottom{
            margin-top: 10px;
            /deep/.el-progress-bar__outer{
                border-radius: 1px;
                background-color: #e4e4e4;
                height: 4px !important;
                /deep/.el-progress-bar__inner{
                    border-radius: 1px;
                    background-color:#2980ff;
                }
            }
        }
    }
}
</style>
